import 'package:flutter/material.dart';
import 'package:kasax_demos2/pratacties/douban/entrys/common_entry.dart';
import 'package:kasax_demos2/pratacties/douban/pages/group/page_group.dart';
import 'package:kasax_demos2/pratacties/douban/pages/home/page_home.dart';
import 'package:kasax_demos2/pratacties/douban/pages/mall/page_mall.dart';
import 'package:kasax_demos2/pratacties/douban/pages/profile/page_profile.dart';
import 'package:kasax_demos2/pratacties/douban/pages/subjects/page_subjects.dart';

class HomeDouban extends StatefulWidget {
  const HomeDouban({Key? key}) : super(key: key);

  @override
  _HomeDoubanState createState() => _HomeDoubanState();
}

class _HomeDoubanState extends State<HomeDouban> {
  List<NavItem> _appbarsItem = [
    NavItem(Icons.home, "首页"),
    NavItem(Icons.video_library_outlined, "书影集"),
    NavItem(Icons.group_work_outlined, "小组"),
    NavItem(Icons.store_mall_directory, "市集"),
    NavItem(Icons.people_rounded, "我的")
  ];

  List<Widget> _pageList = [
    PageHome(),
    PageSubjects(),
    PageGroups(),
    PageMall(),
    PageProfile()
  ];
  int _currentIndex = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Douban"),
        elevation: 0,
        centerTitle: true,
      ),
      body: IndexedStack(
        children: _pageList,
        index: _currentIndex,
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
        selectedItemColor: Colors.green,
        unselectedItemColor: Colors.grey,
        items: _appbarsItem
            .map((e) => BottomNavigationBarItem(
                icon: Icon(e.icon), title: Text(e.title)))
            .toList(),
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}
